package com.example.moonshine.baidumap.Service;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.provider.Settings;
import android.widget.Toast;

import com.example.moonshine.baidumap.View.Activity.BroadCastManager;
import com.example.moonshine.baidumap.View.Activity.MainActivity;

public class MainService {

    /**
     * g监听gps是否打开
     * 跳转到gps打开目录去打开gps
     * @param context
     */
    public void openGps(final Context context) {
        LocationManager locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
        // 判断GPS模块是否开启，如果没有则开启
        if (!locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
            Toast.makeText(context, "请打开GPS", Toast.LENGTH_SHORT).show();
            final android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(context);
            dialog.setTitle("请打开GPS连接");
            dialog.setMessage("为了方便任务通知您，请先打开GPS");
            dialog.setPositiveButton("设置", new android.content.DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                    // 转到手机设置界面，用户设置GPS
                    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    Toast.makeText(context, "打开后直接点击返回键即可，若不打开返回下次将再次出现", Toast.LENGTH_SHORT).show();
                    ((Activity)(context)).startActivityForResult(intent, 0); // 设置完成后返回到原来的界面
                }
            });
            dialog.setNeutralButton("取消", new android.content.DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                    arg0.dismiss();
                }
            });
            dialog.show();
        }
    }
    /**
     *    //发送广播
     * @param index
     */
    public void sendBroadcast(String index, Context context){

        Intent intent = new Intent();
        intent.putExtra("order", index);
        intent.setAction("fragment_home_left");
        BroadCastManager.getInstance().sendBroadCast(((Activity)(context)), intent);
    }

}
